﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;
using Helper;
using System.ComponentModel;
namespace CoreData
{
    public class Audit
    {
     
            public long ID{get;set;}
            public string Code { get; set; }
          [Description("Hành động")]
            public string Action{get;set;}
        [Description("Chức năng")]
            public string Module { get; set; }
        [Description("Nội dung")]
        public string Description { get; set; }
        [Description("Ngày hoạt động")]
            public DateTime ModifiedDate{get;set;}
            public long UserID{get;set;}
        
        [Description("Tài khoản")]
            public string UserExt {get;set;}
        [Description("Ngày")]
            public int DayExt { get; set; }
        [Description("Tháng")]
            public int MonthExt { get; set; }
        [Description("Năm")]
            public int YearExt { get; set; }
         
        public Audit()
            {
                Module = "";
                Action = ""; 
                            Description ="";   
        }
        
       static Audit DynamicCast<T>(object row_data, object row_header) where T : Audit
       {
           // row_data : DataRow
           // row_header : DataColumnCollection
           Audit ret = new Audit();
           DataRow dt = (DataRow)row_data;

           foreach (DataColumn column in (DataColumnCollection)row_header)
           {
               switch (column.ColumnName)
               {
                      case  "ID":
                        ret.ID = ConvertObject.ToLong(dt[column]);
                       break;
                      case "Code":
                       ret.Code = ConvertObject.ToString(dt[column]);
                       break;
                      case "Action":
                       ret.Action = ConvertObject.ToString(dt[column]);
                       break;
                      case "Module":
                       ret.Module = ConvertObject.ToString(dt[column]);
                       break;
                      case  "ModifiedDate":
                        ret.ModifiedDate = ConvertObject.ToDateTime(dt[column]);
                        ret.DayExt = ret.ModifiedDate.Day;
                        ret.MonthExt = ret.ModifiedDate.Month;
                        ret.YearExt = ret.ModifiedDate.Year;
                       break;
                      case  "UserID":
                        ret.UserID = ConvertObject.ToLong(dt[column]);
                       break;
                     
                      case  "Description":
                        ret.Description = ConvertObject.ToString(dt[column]);
                       break;
                   case "UserName":
                       ret.UserExt = ConvertObject.ToString(dt[column]);
                       break;
                   default:
                       break;
               }
           }

           return ret;
       }
        
    }
}
